/*    */ package blockbuster.components.expiration;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.components.IComponentParticleInitialize;
/*    */ import blockbuster.components.IComponentParticleUpdate;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ import com.google.gson.JsonParseException;
/*    */ 
/*    */ public class BedrockComponentParticleLifetime
/*    */   extends BedrockComponentBase implements IComponentParticleInitialize, IComponentParticleUpdate {
/* 17 */   public MolangExpression expression = MolangParser.ZERO;
/*    */   
/*    */   public boolean max;
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 23 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 25 */     JsonObject element = elem.getAsJsonObject();
/* 26 */     JsonElement expression = null;
/*    */     
/* 28 */     if (element.has("expiration_expression")) {
/*    */       
/* 30 */       expression = element.get("expiration_expression");
/* 31 */       this.max = false;
/*    */     }
/* 33 */     else if (element.has("max_lifetime")) {
/*    */       
/* 35 */       expression = element.get("max_lifetime");
/* 36 */       this.max = true;
/*    */     }
/*    */     else {
/*    */       
/* 40 */       throw new JsonParseException("No expiration_expression or max_lifetime was found in minecraft:particle_lifetime_expression component");
/*    */     } 
/*    */     
/* 43 */     this.expression = parser.parseJson(expression);
/*    */     
/* 45 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 51 */     JsonObject object = new JsonObject();
/*    */     
/* 53 */     object.add(this.max ? "max_lifetime" : "expiration_expression", this.expression.toJson());
/*    */     
/* 55 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void update(BedrockEmitter emitter, BedrockParticle particle) {
/* 61 */     if (!this.max && this.expression.get() != 0.0D)
/*    */     {
/* 63 */       particle.dead = true;
/*    */     }
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void apply(BedrockEmitter emitter, BedrockParticle particle) {
/* 70 */     if (this.max) {
/*    */       
/* 72 */       particle.lifetime = (int)(this.expression.get() * 20.0D);
/*    */     }
/*    */     else {
/*    */       
/* 76 */       particle.lifetime = -1;
/*    */     } 
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\expiration\BedrockComponentParticleLifetime.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */